package com.example.mobile203zlw0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView textView,textView2;
    private RadioGroup radioGroup1;
    private RadioButton rbJiaoche;
    private RadioButton rbMpv;
    private RadioButton rbSuv;
    private RadioGroup radioGroup2;
    private RadioButton rb01;
    private RadioButton rb02;
    private RadioButton rb03;
    private RadioButton rb04;
    private Button buDanji;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        textView2=findViewById(R.id.textView2);
        textView = (TextView) findViewById(R.id.textView);
        radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup_1);
        rbJiaoche = (RadioButton) findViewById(R.id.rb_jiaoche);
        rbMpv = (RadioButton) findViewById(R.id.rb_mpv);
        rbSuv = (RadioButton) findViewById(R.id.rb_suv);
        radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
        rb01 = (RadioButton) findViewById(R.id.rb_01);
        rb02 = (RadioButton) findViewById(R.id.rb_02);
        rb03 = (RadioButton) findViewById(R.id.rb_03);
        rb04 = (RadioButton) findViewById(R.id.rb_04);
        buDanji = (Button) findViewById(R.id.bu_danji);
        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rb_jiaoche:
                        Log.i("jiaoche","轿车车型");
                        break;
                    case R.id.rb_mpv:
                        Log.i("mvp","mvp");
                        break;
                    case R.id.rb_suv:
                        Log.i("SUV","suv");
                        break;
                }
            }
        });
        radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_01:
                        Log.i("01","车间1");
                        break;
                    case R.id.rb_02:
                        Log.i("02","车间2");
                        break;
                    case R.id.rb_03:
                        Log.i("03","车间3");
                        break;
                    case R.id.rb_04:
                        Log.i("04","车间4");
                        break;
                }
                }
        });
        buDanji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               int up=radioGroup1.getCheckedRadioButtonId();
                int up2=radioGroup2.getCheckedRadioButtonId();
//               if (up!=-1){
//                   RadioButton radioButton=findViewById(up);
                   if (up==R.id.rb_jiaoche & up2==R.id.rb_02){
                        textView2.setText("选择正确");
                       Log.i("输入1","选择正确");
                   }else if(up==0 & up2==0 ) {
                       Log.i("输入3","未选择");
                       Toast.makeText(MainActivity.this, "请选择", Toast.LENGTH_SHORT).show();
                   }
                   else if (up!=R.id.rb_jiaoche & up2!=R.id.rb_02){
                       textView2.setText("选择不正确");
                       Log.i("输入2","选择不正确");
                   }
            }
        });
    }
}